#include "q_a.h"
#include "ui_q_a.h"
#include <QSqlQuery>
Q_A::Q_A(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Q_A)
{  cnt=0;
    ui->setupUi(this);
   vec.push_back(Question("下列符合读者守则的是","破坏所借图书","逾期不还","按照规定续借","将未借阅的图书带出本馆",3));
   vec.push_back(Question("下列不符合读者守则的是","知晓并遵守各类图书的可借阅时长","超过规定次数续借","在馆内阅读未借阅的图书","在阅览室自习",2));
   vec.push_back(Question("对于无法按时归还的图书，正确的做法是","超过规定次数续借","不还了","买下来","按照规定续借或在就近的分馆归还",4));
   vec.push_back(Question("在图书馆用物品长期占座会导致的后果是：","失去信用值","不会有任何后果","物品被管理员清理","取消在本馆阅读资格一周",3));
   vec.push_back(Question("影像光碟借阅时长上限是：","1周","15天","1个月","2个月",2));
   vec.push_back(Question("破坏新版图书的后果是：","按书本原价赔偿","失去信用值","按书本原价3~5倍赔偿","按书本原价10倍以上赔偿",3));
   vec.push_back(Question("能否在图书馆饮食：","能","不能","领导可以","视图书馆人数而定",2));
}

Q_A::~Q_A()
{
    delete ui;
}

void Q_A::refresh()
{if(cnt>=vec.size())
    {
        QMessageBox::information(this,tr("提示对话框"),tr("答题结束，全部正确，信用值已恢复！"), QMessageBox::Ok);
        Readersql rsql;
        QSqlQuery sql(rsql.m_db);
        global::overtime="0";
        QString sqlstr = QString("update Reader set book_overtime = 0 where ID='%1'").arg(ID);
        sql.exec(sqlstr);
        close();
              return;
    }
 ui->label->setText(vec[cnt].q);
 ui->A->setText(vec[cnt].A);
 ui->B->setText(vec[cnt].B);
 ui->C->setText(vec[cnt].C);
 ui->D->setText(vec[cnt].D);

}


void Q_A::on_bnA_clicked()
{if(vec[cnt].answer==1)
    {
        cnt++;
    }
 else
    {QMessageBox::information(this,tr("提示对话框"),tr("答错了，请重新进入系统作答！"), QMessageBox::Ok);
       cnt=0;
      close();
      return;

    }
refresh();
}


void Q_A::on_bnB_clicked()
{if(vec[cnt].answer==2)
    {
        cnt++;
    }
 else
  {QMessageBox::information(this,tr("提示对话框"),tr("答错了，请重新进入系统作答！"), QMessageBox::Ok);
        cnt=0;
         close();
         return;

  }
refresh();

}


void Q_A::on_bnC_clicked()
{if(vec[cnt].answer==3)
    {
        cnt++;
    }
 else
  {QMessageBox::information(this,tr("提示对话框"),tr("答错了，请重新进入系统作答！"), QMessageBox::Ok);
        cnt=0;
         close();
         return;

  }
refresh();

}


void Q_A::on_pushButton_4_clicked()
{if(vec[cnt].answer==4)
    {
        cnt++;
    }
 else
  {QMessageBox::information(this,tr("提示对话框"),tr("答错了，请重新进入系统作答！"), QMessageBox::Ok);
        cnt=0;
         close();
         return;

  }
refresh();

}

